<template>
	<view>
		<u-navbar height="50" back-icon-color="#333" 
			title="我的银行卡" title-color="#333" title-size="36"></u-navbar>
		<view class="content">
			<view class="cardView" v-for="(item,index) in bankItem" :key="index" @click="select">
				<view class="cardTextView">
					<view class="cardTitle">{{item.bank}}</view>
					<view class="cardTitle">{{item.cardholder}}</view>
					<view class="cardText">{{item.bank_card_number}}</view>
				</view>
				<view class="unBandBtn" @click="onUnBand(item)">
					<text>解除绑定</text>
				</view>
			</view>
			<view class="addCard" @click="onAddBank()">+添加银行卡</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bankItem: []
			}
		},
		onShow() {
			// this.initBank();
		},
		methods: {
			onClose() {
				uni.navigateBack({
					delta: 1
				});
			},
			initBank() {
				let self = this
				self.$user.bankCardList({}, true).then(res => {
					self.bankItem = res.data;
				});
			},
			onUnBand(item) {
				uni.navigateTo({
					url:'/other/unband-card/unband-card?item=' + JSON.stringify(item)
				})
			},
			onAddBank() {
				uni.navigateTo({
					url:'/other/add-card/add-card'
				})
			},
			select(){
				// B页面传递：
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2]; //上一个页面
				let object={
				    name:"我们都有一个家，名字叫中国",
				    age:"上下五千年",
				}
				prevPage.onShow(object);
				uni.navigateBack();
			}
		}
	}
</script>

<style>
	@import url('my-card.css');

	page {
		background: #F2F2F2;
	}
</style>
